/* For Watchlist Flash*/
/* colors setting for Theme*/
if (!QS_Style) {
    var QS_Style = {
        redFontColor: '#ff0000',
        redFontBG: '#FFC8C8',
        greenFontColor: '#008000',//
        greenFontBG: '#CDFFD7',
        normalFontBG:'#ccc',
        layouthelperBG:"#fff",
        redFlashFontColor:'#ff0000',
        greenFlashFontColor:'#008000',
        normalFlashFontColor:'#121212',
        chart:{
            tickerColors:["#728fb2", "#9b0033","#e96610","#f1ad02","#9faa00","#006065","#809aba","#e1b2c1",
                "#e2e5b2","#293f6f","#fbe6b3","#f2a370","#b2cfd0", "#bec5d4","#c5cc66","#f8d1b7","#c36685","#c9cbcb"],
            fillColors:{pChart:"#c9d2dd",vChart:"#2f4880",sChart:"#d9dfeb",minichartPchart:"#004DBC"}
        },
        flot:{grid:{color:"#545454",tickColor:"#dddddd"},alpha:0.7}
    };
}

if (!Util) {
    var Util = {};
}
Util.textKey = $.browser.msie?"innerText":"textContent"; 
Util.formatDoubledata =function(value,type,decimalpos,needformat,needunit,seperate,unmark,stayzs){
    var depos = "",returnvalue = "";
    if(String(value).trim().length==0) return returnvalue;
    if (typeof decimalpos=='undefined') {
        switch (type) {
            case "20"://forex  5
                depos = 5;
                break;
            case "1"://stock/fund
                depos = 2;
                break;
            case "10"://ETF
                depos = 2;
                break;
            default:
                depos = 2;
        }
    }
    else{
        depos = decimalpos;
    }
    if(needformat&&typeof QS_NumFmt!="undefined" && typeof QS_NumFmt.Fmt2 =='function'){
        if(unmark){
            returnvalue = QS_NumFmt.FmtUnMark(value,needunit||false,depos, needformat||false,stayzs||false);//n, isC, d,isFormat
        }else{
            returnvalue = QS_NumFmt.Fmt2(value,needunit||false,seperate||"",depos, needformat||false);//n, isC, sep, d,isFormat
        }
    }else{
        returnvalue = parseFloat(value).toFixed(depos);
    }
    return returnvalue;
}
/*  Some functions provided to format the date or numbers*/
var d = new Date();
var startTick = new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
Util.FDate = function(value,islong) {
    var t = startTick + parseInt(value) * 1000;
    var dt = new Date(t);
    return (dt == null) ? "--" :(islong?QS_DateFmt.getLongTime(dt):QS_DateFmt.getTimeString(dt));
};
Util.flashWithDirectional = function (el, v, c, isUp){ //v:current data, c:old data
    if(!v || !c){
        el.style.cssText = "background-color:" + QS_Style.normalFontBG + ";color:" + (isUp ? QS_Style.greenFlashFontColor : QS_Style.redFlashFontColor);
    }else{
        el.style.cssText = "background-color:" + ((v > c) ? QS_Style.greenFontBG : QS_Style.redFontBG)  + ";color:" + (isUp ? QS_Style.greenFlashFontColor : QS_Style.redFlashFontColor);
    }
    setTimeout(function(){
        el.style.cssText = "background-color:;color:" + (isUp ? QS_Style.greenFontColor : QS_Style.redFontColor);
    }, 300);
};
Util.flash = function (el, v, c){ //v:current data, c:old data
    if (!v || !c) {
        el.style.cssText = "background-color:" + QS_Style.normalFontBG + ";color:" + QS_Style.normalFlashFontColor;
    }
    else {
        el.style.cssText = "background-color:" + ((v > c) ? QS_Style.greenFontBG : QS_Style.redFontBG) + ";color:" + QS_Style.normalFlashFontColor;
    }
    setTimeout(function(){
        el.style.cssText = "background-color:;color:;";
    }, 300);
};
Util.isValid = function(ob,checkUndefined,checkNull,checkEmpty,checkZero){
    var o = void(0);
    if(checkUndefined&&ob==o){
        return false;
    }
    if(checkNull&&ob==null){
        return false;
    }
    if(typeof ob=="string"){
        if(checkEmpty&&$.trim(ob)==''){
            return false;
        }
        if(checkZero&&!isNaN(ob)&&parseFloat(ob)==0){
            return false;
        }
    }
    return true;
};
Util.isFunction = function(f){
    return typeof f =='function';
};

Util.Window = {
    getHostAddress:function(){
        return String.format("{0}//{1}{2}",window.location.protocol,window.location.host,window.location.pathname);
    },
    getLocationArg:function(){
        var urlCfg={};
        var __url = window.location.search;
        if (__url != "" && __url.length > 0) {
            __url = __url.substr(__url.indexOf("?")+1);
        }
        var carr = __url.split("&");
        for (var i = 0; i < carr.length; i++) {
            var item = carr[i].split("=");
            urlCfg[$.trim(item[0])] = $.trim(item[1]);
        }
        return urlCfg;
    },
    genURL:function(data){
        return String.format("{0}?{1}",api_common_openwindow.getHostAddress(),$.param(data));

    },
    genExternalURL:function(domain,data){
        return String.format("{0}?{1}",domain,$.param(data));

    },
    openWindow:function(URL,title){
        window.open(URL,title, "toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=1000,height=800");
    }
};

String.format = function(str) {
    if(typeof(str)!="string")return "";
    if (arguments.length <= 1)
        return str;
    var lastIndex = arguments.length - 2;
    for (var i = 0; i <= lastIndex; i++)
        str = str.replace(new RegExp("\\{" + i + "\\}", "gi"), arguments[i + 1]);
    return str;
};
